home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 40 / Amiga Format CD40 (1999-05-11)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-06].iso / -readerstuff- / paul_qureshi / info / sine1.txt < prev    next >
Text File  |  1999-03-27  |  4KB  |  105 lines

  1.  
  2. From: NTFL15A@prodigy.com (Lynn Boyett)
  3. Newsgroups: comp.graphics.algorithms
  4. Subject: Re: Sine (or Cosine) Algo. needed
  5. Date: 28 Dec 1996 06:08:07 GMT
  6. Organization: Prodigy Services Company  1-800-PRODIGY
  7. Lines: 102
  8. Distribution: world
  9. Message-ID: <5a2dg7$1s1e@usenetw1.news.prodigy.com>
  10. References: <32c15a48.41d8@popalex1.linknet.net> <32c3e80c.6716@nstl.com> <32c4daba.4406@sn.no>
  11. NNTP-Posting-Host: innugap4-int.news.prodigy.com
  12. X-Newsreader: Version 1.2
  13.  
  14. Francois wrote about formula for sine and cosine functions.
  15.  
  16. The formula used are from the Taylor series for sine and cosine 
  17. functions.
  18.  
  19.                   oo                                    3    5    7
  20.                   __    (2*n-1)          n+1           x    x    x
  21.         sin(x) = \     x           * (-1)       =  x - -- + -- - -- + ...
  22.                  /__   ------------------              3!   5!   7!
  23.                 n = 1     (2*n-1) !
  24.                   
  25.  
  26.                   oo                                  2    4    6
  27.                   __    (2*n+1)          n           x    x    x
  28.         cos(x) = \     x          *  (-1)    =   1 - -- + -- - -- + ...
  29.                  /__   ------------------            2!   4!   6!
  30.                 n = 0     (2*n+1) !
  31.  
  32.  
  33. This is true for all x such that (-oo < x < +oo).  This is radian
  34. measure.
  35.  
  36. With an increase in speed of 10% to 35% (as he reported), it would 
  37. be an advantage over the library calculations.
  38.  
  39. Speed could be increased by not duplicating calculations, such as
  40. the following:
  41.                   2
  42.         let u := x   , then
  43.  
  44.         the expanded equations become:
  45.  
  46.                               2    3
  47.                         u    u    u                         2
  48.         sin(x) = x*(1 - -- + -- - -- + ...       where u = x
  49.                         3!   5!   7!
  50.  
  51.                               2    3
  52.                         u    u    u                         2
  53.         cos(x) =    1 - -- + -- - -- + ...       where u = x
  54.                         2!   4!   6!
  55.  
  56.  
  57. Calculate 'u' once and reuse it in the rest of the equations instead
  58. of calculating 'x*x' each time.
  59.  
  60. By using a table for the reciprical of factorials and with the
  61. calculation of x*x the process would be faster.
  62.  
  63. In Assembly, the coefficent values could be in two tables with the
  64. references to them being the only difference.
  65.  
  66. Then there would be an 'overlap' in that
  67.  
  68.  
  69.                                2    3
  70.                          u    u    u
  71.                      (- --  + -- -  -- + ...
  72.                          2!   4!   6!
  73.                          3!   5!   7!
  74.  
  75. is the same in both equations.
  76.  
  77. Remember that the routine would call (relative, etc) either 2!,4!,6!
  78. or 3!,5!,7!.  Actually, you would call the recipricals.  You would
  79. then add one to the answer.  This is Cosine.  With 'even' factorials.
  80.  
  81. And for Sine you would need a little more work.  Multiple by the
  82. original value 'x'.  With the 'odd' factorials.
  83.  
  84. This overlap would also reduce the space required.
  85.  
  86. Also, knowing the cooefficients can allow any programmer the precision
  87. that they want - like 6 decimal places or 16 places (if their computer
  88. can handle it) or even more.
  89.  
  90. ****************************************************************
  91. A very elementary routine would be
  92.  
  93. sine:   save the original value in a holding place
  94.         reference the recipricals of factorials by relative, etc.
  95.         goto around
  96. cosine: save a one in a holding place
  97.         reference the recipricals of factorials by relative, etc.
  98. around: calculate the square of the original value
  99.         compute the main equation(s)
  100.         add one
  101.         multiply by the value in the holding place from above
  102.             (either one or the original value)
  103.  
  104. This could be cleaned up a lot.
  105.